home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / unix / c / read < prev    next >
Text File  |  1996-11-09  |  1KB  |  56 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/read,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.3 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: read,v $
  10.  * Revision 1.3  1996/10/30 22:04:51  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.2  1996/05/06 09:01:35  unixlib
  14.  * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
  15.  * Saved for 3.7a release.
  16.  *
  17.  * Revision 1.1  1996/04/19 21:35:27  simon
  18.  * Initial revision
  19.  *
  20.  ***************************************************************************/
  21.  
  22. static const char rcs_id[] = "$Id: read,v 1.3 1996/10/30 22:04:51 unixlib Rel $";
  23.  
  24. #include <errno.h>
  25. #include <fcntl.h>
  26. #include <unistd.h>
  27.  
  28. #include <sys/syslib.h>
  29. #include <sys/dev.h>
  30. #include <sys/unix.h>
  31.  
  32. __ssize_t
  33. read (int fd, ptr_t data, size_t nbyte)
  34. {
  35.   register struct file *f;
  36.  
  37.   if (BADF (fd))
  38.     {
  39.       errno = EBADF;
  40.       return (__ssize_t)-1;
  41.     }
  42.  
  43.   f = __u->file + fd;
  44.  
  45.   if ((f->oflag & O_OMASK) == O_WRONLY)
  46.     {
  47.       errno = EBADF;
  48.       return (__ssize_t)-1;
  49.     }
  50.  
  51.   /* Increment the number of times we have has to read from a device.  */
  52.   __u->usage.ru_inblock++;
  53.  
  54.   return (__ssize_t)__funcall ((*(__dev[major (f->dev)].read)), (minor (f->dev), data, nbyte, f));
  55. }
  56.